package com.kun.base.fs;

import com.xiaoleilu.hutool.io.IoUtil;

import java.io.*;

/**
 * @author likun
 * 2018/3/15 11:07
 * 本地文件存储系统
 **/
public class NativeFileSystem implements FileSystem {

    @Override
    public String getPathSeparator() {
        return File.pathSeparator;
    }

    @Override
    public long write(String path, InputStream inputStream) throws IOException {
        OutputStream outputStream = new FileOutputStream(path);
        long length=IoUtil.copy(inputStream, outputStream);
        outputStream.close();
        return length;
    }

    @Override
    public InputStream read(String path) throws FileNotFoundException {
        return new FileInputStream(path);
    }

    @Override
    public boolean delete(String path) {
        File file = new File(path);
        return file.delete();
    }

    @Override
    public boolean exists(String path) {
        return new File(path).exists();
    }

    @Override
    public boolean isDirectory(String path) {
        return new File(path).isDirectory();
    }

    @Override
    public boolean isFile(String path) {
        return new File(path).isFile();
    }

    @Override
    public long length(String path) {
        return new File(path).length();
    }

    @Override
    public String[] list(String path) {
        return new File(path).list();
    }

    @Override
    public boolean mkdir(String path) {
        return new File(path).mkdir();
    }

    @Override
    public boolean mkdirs(String path) {
        return new File(path).mkdirs();
    }

    @Override
    public boolean rename(String fileName, String newFileName) {
        File file = new File(fileName);
        return file.renameTo(new File(newFileName));
    }
}
